'use strict';
const db = uniCloud.database();
const uniID = require('uni-id')
exports.main = async (event, context) => {
	const uniIDIns = uniID.createInstance({
	  context
	})
	let payload={}
	payload = await uniIDIns.checkToken(event.uniIdToken)
	if (payload.code && payload.code > 0) {
		return payload
	}
	event.user_id = payload.uid;
	event.commentTotal=0;
	//event为客户端上传的参数
	console.log('event : ', event)
	let res;
	if(event.type=='image'){
		const collection = db.collection('memory')
	    res=await collection.add(event)
		return res
	}else{
		const collection = db.collection('memory-video')
		res=await collection.add(event)
		console.log(res)
		
	}
	
	//返回数据给客户端
	return res
};
